package com.campus.course.controller;

import com.campus.common.result.Result;
import com.campus.course.dto.entity.Courses;
import com.campus.course.dto.form.UpdateCourseForm;
import com.campus.course.dto.vo.CourseListVO;
import com.campus.course.service.ICoursesService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
@Tag(name = "课程服务")
public class CourseController {

    @Autowired
    private ICoursesService coursesService;

    @ApiOperation(value = "查找所有课程")
    @GetMapping("/get-all-course")
    public Result<List<CourseListVO>> selectAllCourses () {
        return Result.success(coursesService.selectAllCourses());
    }

    @ApiOperation(value = "搜索课程")
    @GetMapping("/search-course/{keyWords}")
    public Result searchCourses (@PathVariable("keyWords") String keyWords) {
        return coursesService.searchCourse(keyWords);
    }

    @ApiOperation(value = "增加课程")
    @PostMapping("/add-course")
    public Result addCourse (@RequestBody Courses course) {
        return coursesService.addCourse(course);
    }

    @ApiOperation(value = "修改课程")
    @PostMapping("/update-course")
    public Result updateCourse(@RequestBody UpdateCourseForm updateCourseForm) {
        return coursesService.updateCourse(updateCourseForm);
    }

    @ApiOperation(value = "删除课程")
    @DeleteMapping("/delete-course/{courseId}")
    public Result deleteCourse (@PathVariable("courseId") int courseId) {
        return coursesService.deleteCourse(courseId);
    }

    @ApiOperation(value = "学生已选课程")
    @GetMapping("/stu-courses")
    public Result stuCourses () {
        return coursesService.getStuCourse();
    }

    @ApiOperation(value = "教师所授课程")
    @GetMapping("/tea-courses")
    public Result teacherGetCourses () {
        return coursesService.teacherGetCourses();
    }
}
